<?php

namespace App\Http\Middleware;

use App\User;
use Closure;

class homeLoginMiddleware {
	/**
	 * Handle an incoming request.
	 *
	 * @param  \Illuminate\Http\Request  $request
	 * @param  \Closure  $next
	 * @return mixed
	 */
	public function handle($request, Closure $next) {
		if (!session('id')) {
			return redirect('/login');
		} else {
			$user = User::find(session('id'));
			if (!$user || $user->status == 0) {
				return redirect('/login');
			}
		}
		return $next($request);
	}
}
